﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using University.Workshop.Presenters.OtbData.Read;
using System.IO;

namespace University.Workshop.Presentation.OTBData.Read
{
    /// <summary>
    /// Interaction logic for PageFirstStepReadOtbData.xaml
    /// </summary>
    public partial class PageFirstStepReadOtbData : Page, IFirstStepForRead
    {
        PresenterReadOtbData pInternal;
        PresenterReadFirstStep pReadFirstStep;

        public PageFirstStepReadOtbData(PresenterReadOtbData pExternal)
        {
            InitializeComponent();
            this.pInternal = pExternal;
            pReadFirstStep = new PresenterReadFirstStep(this);
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            App.Current.MainWindow.Title = "Ver Datos OTB";
        }

        #region Fields
        public string Name
        {
            set
            {
                nameLbl.Content = value;
            }
        }

        public string Managment
        {

            set
            {
                managmentLbl.Content = value;
            }
        }

        public int? ExpirationDay
        {
            set
            {
                expirationDayLbl.Content = value;
            }
        }

        public string Background
        {
            set
            {
                if (!string.IsNullOrWhiteSpace(value))
                {
                    if (File.Exists(value))
                    {
                        BitmapImage image = new BitmapImage();
                        using (FileStream stream = File.OpenRead(value))
                        {
                            image.BeginInit();
                            image.StreamSource = stream;
                            image.CacheOption = BitmapCacheOption.OnLoad;
                            image.EndInit(); // load the image from the stream
                        } // close the stream
                        backgroundImg.Source = image;
                    }
                }
            }
        }
        #endregion

        public void UpdateViewData()
        {
            pReadFirstStep.UpdateViewData();
        }

        public void GoNextPage()
        {
            pInternal.GoStepTwo();
        }

        public void GoBackPage()
        {

        }

        public Model.OtbData OtbDataToRead
        {
            get;
            set;
        }
    }
}
